/*
 * Copyright 2008 Karel Klic.
 * This file is part of Oslavanský Bot.
 * 
 * Oslavanský Bot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package categorybot;

import java.util.regex.*;

public class PatternFactory {

  static private Pattern header2Pattern = Pattern.compile("^[^=\n]*==[\\s*\\p{L}[\\p{L}\t ]*\\s*]+==[^=\n]*$", Pattern.MULTILINE);
  static private Pattern header3Pattern = Pattern.compile("^[^=\n]*===[\\s*\\p{L}[\\p{L}\t ]*\\s*]+===[^=\n]*$", Pattern.MULTILINE);
  static private Pattern categoryPattern = Pattern.compile("\\[\\[\\s*Kategorie:[ \t]*\\p{L}[\\p{L}\t ]*\\s*\\]\\]", Pattern.MULTILINE);

  /**
   * Pattern that matches any header of level 2.
   * Language headers has this header level in Czech Wiktionary.
   * Example of level 2 header: "== čeština ==".
   * @return
   */
  static public Pattern getHeader2Pattern() {
    return header2Pattern;
  }

  /**
   * Pattern that matches level 2 header with specified title.
   * @param title
   * Header text such as "čeština", "angličtina".
   * @return
   * Pattern that matches.
   */
  static public Pattern getHeader2Pattern(String title) {
    String regex = "^[^=\n]*==\\s*" + Pattern.quote(title) + "\\s*==[^=\n]*$";
    return Pattern.compile(regex, Pattern.MULTILINE);
  }

  /**
   * Pattern that matches any header of level 3.
   * Word class headers has this header level in Czech Wiktionary.
   * Example of level 3 header: "=== podstatné jméno ===".
   * @return
   * Pattern that matches for example "=== podstatné jméno ===", but it does
   * not match "== podstatné jméno ==" nor "==== podstatné jméno ====".
   */
  static public Pattern getHeader3Pattern() {
    return header3Pattern;
  }
  
  /**
   * Pattern that matches level 3 header with specified title.
   * @param title
   * Header text such as "podstatné jméno", "sloveso".
   * @return
   * Pattern that matches for example "=== podstatné jméno ===", but it does
   * not match "== podstatné jméno ==" nor "==== podstatné jméno ====".
   */
  static public Pattern getHeader3Pattern(String title) {
    String regex = "^[^=\n]*===\\s*" + Pattern.quote(title) + "\\s*===[^=\n]*$";
    return Pattern.compile(regex, Pattern.MULTILINE);
  }  
  
  static public Pattern getCategoryPattern() {
    return categoryPattern;
  }
  
  /**
   * Pattern that matches the category link with specified category name.
   * @param categoryName
   * Category name such as "Anglická slovesa", "cs-Zvířata".
   * @return
   * Pattern that matches for example "[[Kategorie:Anglická slovesa]]".
   */
  static public Pattern getCategoryPattern(String categoryName) {
    String regex = "\\[\\[\\s*Kategorie:[ \t]*" + Pattern.quote(categoryName) + "\\s*\\]\\]";
    return Pattern.compile(regex, Pattern.MULTILINE);
  }
}
